package org.jxht.web.api;

import org.jxht.dto.TeaCouDto;
import org.jxht.service.TeaCouService;
import org.jxht.util.GsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * Created by huang on 2017/3/20 0020.
 */
@Controller
@RequestMapping("JxhtWeb/StuCouController")
public class TeaCouController {

    @Autowired
    private TeaCouService teaCouService;

    /**
     * 教师申请课程记录
     * @param requestId 执行该功能的用户Id
     * @param requestJson Json字符串
     * @return String
     */
    @RequestMapping(value = "/{requestId}/addTeaCouRecord")
    public String addTeaCouRecord(@PathVariable(value = "requestId")int requestId,
                                  @RequestParam(value = "requestJson")String requestJson){
        List<TeaCouDto> dtos = GsonUtil.parseJsonArrayWithGson(requestJson,TeaCouDto.class);
        for(TeaCouDto dto:dtos){
            teaCouService.insertTeaCouService(dto);
        }
        return "SUCCESS";
    }

    /**
     * 更新教师课程记录
     * @param requestId 执行该功能的用户Id
     * @param requestJson Json字符串
     * @return
     */
    @RequestMapping(value = "/{requestId}/changeTeaCouRecord")
    public String changeTeaCouRecord(@PathVariable(value = "requestId")int requestId,
                                     @RequestParam(value = "requestJson")String requestJson){
        List<TeaCouDto> dtos = GsonUtil.parseJsonArrayWithGson(requestJson,TeaCouDto.class);
        for(TeaCouDto dto:dtos){
            teaCouService.updataTeaCouService(dto);
        }
        return "SUCCESS";
    }

    /**
     * 删除教师课程记录
     * @param teaCouId
     * @return String
     */
    @RequestMapping(value = "/{teaCouId}/deleteTeaCouRecord")
    public String deleteTeaCouRecord(@PathVariable(value = "teaCouId")int teaCouId){
        teaCouService.deleteTeaCouService(new TeaCouDto(teaCouId));
        return "SUCCESS";
    }
}
